package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "管理端订单接口")
public class OrderController {
    @Autowired
    private OrderService orderService;
    /**
     * 搜索订单
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("订单搜索参数:{}", ordersPageQueryDTO);
        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 查看订单详情
     */
    @GetMapping("details/{id}")
    public Result<OrderVO> details(@PathVariable Long id) {
        log.info("查看订单详情，订单号id为：{}",id);
        OrderVO orderVO = orderService.selcetOrderDetail(id);
        return Result.success(orderVO);
    }
    /**
     * 用户接单
     */
    @PutMapping("/confirm")
    public Result orderconfirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        log.info("用户接单，接取的订单号为：{}",ordersConfirmDTO);
        orderService.orderconfirm(ordersConfirmDTO);
        return Result.success();
    }
    /**
     * 用户拒单
     */
    @PutMapping("rejection")
    public Result orderrejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("商家拒绝订单，拒绝订单的编号为：{}",ordersRejectionDTO);
        orderService.orderRejection(ordersRejectionDTO);
        return Result.success();
    }
    /**
     * 订单派送
     */
    @PutMapping("/delivery/{id}")
    public Result orderdelivery(@PathVariable Integer id){
        log.info("订单派送，派送的订单id为：{}",id);
        orderService.orderdelivery(id);
        return Result.success();
    }
    /**
     * 订单完成
     */
    @PutMapping("/complete/{id}")
    public Result ordercomplete(@PathVariable Integer id){
        log.info("订单完成，完成的订单id为：{}",id);
        orderService.ordercomplete(id);
        return Result.success();
    }

    /**
     * 订单取消
     */
    @PutMapping("/cancel")
   public  Result ordercancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
    log.info("订单取消{}",ordersCancelDTO);
    orderService.ordercancel(ordersCancelDTO);
    return Result.success();
   }
    /**
     * 各个状态订单数量统计
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        log.info("各个状态订单数量统计");
        OrderStatisticsVO orderStatisticsVO = orderService.getStatistics();
        return Result.success(orderStatisticsVO);
    }
}

